import bcrypt from 'bcrypt';

/**
 * 加密密码
 * @param {string} password - 要加密的密码
 * @param {number} saltRounds - 盐的轮数，默认为10
 * @returns {Promise<string>} - 返回加密后的密码
 */
export const hashPassword = async (password: string, saltRounds: number = 10): Promise<string> => {
  return await bcrypt.hash(password, saltRounds);
};

/**
 * 验证密码
 * @param {string} password - 用户输入的密码
 * @param {string} hashedPassword - 存储的加密密码
 * @returns {Promise<boolean>} - 返回密码是否匹配
 */
export const comparePassword = async (password: string, hashedPassword: string): Promise<boolean> => {
  return await bcrypt.compare(password, hashedPassword);
};